<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="合同编号" prop="contractNo">
        <el-input
          v-model="queryParams.contractNo"
          placeholder="请输入合同编号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="合同年份" prop="contractYear">
        <el-input
          v-model="queryParams.contractYear"
          placeholder="请输入合同年份"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="是否为代购代销" prop="purchaseSaleAgency">
        <el-input
          v-model="queryParams.purchaseSaleAgency"
          placeholder="请输入是否为代购代销"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="项目编号" prop="projectNumber">
        <el-input
          v-model="queryParams.projectNumber"
          placeholder="请输入项目编号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="合同名称" prop="contractName">
        <el-input
          v-model="queryParams.contractName"
          placeholder="请输入合同名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="框架协议" prop="frame">
        <el-input
          v-model="queryParams.frame"
          placeholder="请输入框架协议"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="对方单位名称" prop="counterpartyName">
        <el-input
          v-model="queryParams.counterpartyName"
          placeholder="请输入对方单位名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="联系人" prop="contact">
        <el-input
          v-model="queryParams.contact"
          placeholder="请输入联系人"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="电话" prop="phone">
        <el-input
          v-model="queryParams.phone"
          placeholder="请输入电话"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="合同金额" prop="conteactAmount">
        <el-input
          v-model="queryParams.conteactAmount"
          placeholder="请输入合同金额"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="项目负责人" prop="projectLeader">
        <el-input
          v-model="queryParams.projectLeader"
          placeholder="请输入项目负责人"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="合同签订部门" prop="contractSignDepartment">
        <el-input
          v-model="queryParams.contractSignDepartment"
          placeholder="请输入合同签订部门"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="合同经办人" prop="contractAgent">
        <el-input
          v-model="queryParams.contractAgent"
          placeholder="请输入合同经办人"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="录入情况" prop="inputCondition">
        <el-input
          v-model="queryParams.inputCondition"
          placeholder="请输入录入情况"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="合同签订日期" prop="conteactSignDate">
        <el-date-picker clearable
          v-model="queryParams.conteactSignDate"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择合同签订日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="合同开始时间" prop="conteactStartDate">
        <el-date-picker clearable
          v-model="queryParams.conteactStartDate"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择合同开始时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="合同结束时间" prop="conteactEndDate">
        <el-date-picker clearable
          v-model="queryParams.conteactEndDate"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择合同结束时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="合同结算条款1" prop="settlementClause">
        <el-input
          v-model="queryParams.settlementClause"
          placeholder="请输入合同结算条款1"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="条款金额1" prop="clauseAmount">
        <el-input
          v-model="queryParams.clauseAmount"
          placeholder="请输入条款金额1"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="合同签订情况" prop="contractSignCondition">
        <el-input
          v-model="queryParams.contractSignCondition"
          placeholder="请输入合同签订情况"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="合同执行进度" prop="contractExecuteSchedule">
        <el-input
          v-model="queryParams.contractExecuteSchedule"
          placeholder="请输入合同执行进度"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="开票总额" prop="totalInvoice">
        <el-input
          v-model="queryParams.totalInvoice"
          placeholder="请输入开票总额"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="开票时间1" prop="invoiceTimeOne">
        <el-date-picker clearable
          v-model="queryParams.invoiceTimeOne"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择开票时间1">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="开票金额1" prop="invoiceAmountOne">
        <el-input
          v-model="queryParams.invoiceAmountOne"
          placeholder="请输入开票金额1"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="开票人1" prop="drawerOne">
        <el-input
          v-model="queryParams.drawerOne"
          placeholder="请输入开票人1"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="发票号1" prop="invoiceNumberOne">
        <el-input
          v-model="queryParams.invoiceNumberOne"
          placeholder="请输入发票号1"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="到款总额" prop="receiveTotalAmount">
        <el-input
          v-model="queryParams.receiveTotalAmount"
          placeholder="请输入到款总额"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="到款时间1" prop="receiveTimeOne">
        <el-input
          v-model="queryParams.receiveTimeOne"
          placeholder="请输入到款时间1"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="到款金额1" prop="receiveAmountOne">
        <el-input
          v-model="queryParams.receiveAmountOne"
          placeholder="请输入到款金额1"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['web:contractinformation:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['web:contractinformation:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['web:contractinformation:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['web:contractinformation:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="contractinformationList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="序号" align="center" prop="id" />
      <el-table-column label="合同编号" align="center" prop="contractNo" />
      <el-table-column label="合同类型" align="center" prop="contractType" />
      <el-table-column label="合同年份" align="center" prop="contractYear" />
      <el-table-column label="是否为代购代销" align="center" prop="purchaseSaleAgency" />
      <el-table-column label="项目编号" align="center" prop="projectNumber" />
      <el-table-column label="合同名称" align="center" prop="contractName" />
      <el-table-column label="框架协议" align="center" prop="frame" />
      <el-table-column label="对方单位名称" align="center" prop="counterpartyName" />
      <el-table-column label="客户类型" align="center" prop="clientType" />
      <el-table-column label="联系人" align="center" prop="contact" />
      <el-table-column label="电话" align="center" prop="phone" />
      <el-table-column label="合同金额" align="center" prop="conteactAmount" />
      <el-table-column label="项目负责人" align="center" prop="projectLeader" />
      <el-table-column label="合同签订部门" align="center" prop="contractSignDepartment" />
      <el-table-column label="合同经办人" align="center" prop="contractAgent" />
      <el-table-column label="录入情况" align="center" prop="inputCondition" />
      <el-table-column label="合同签订日期" align="center" prop="conteactSignDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.conteactSignDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="合同开始时间" align="center" prop="conteactStartDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.conteactStartDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="合同结束时间" align="center" prop="conteactEndDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.conteactEndDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="合同结算条款1" align="center" prop="settlementClause" />
      <el-table-column label="条款金额1" align="center" prop="clauseAmount" />
      <el-table-column label="合同签订情况" align="center" prop="contractSignCondition" />
      <el-table-column label="合同执行进度" align="center" prop="contractExecuteSchedule" />
      <el-table-column label="开票总额" align="center" prop="totalInvoice" />
      <el-table-column label="开票时间1" align="center" prop="invoiceTimeOne" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.invoiceTimeOne, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="开票金额1" align="center" prop="invoiceAmountOne" />
      <el-table-column label="开票人1" align="center" prop="drawerOne" />
      <el-table-column label="发票号1" align="center" prop="invoiceNumberOne" />
      <el-table-column label="到款总额" align="center" prop="receiveTotalAmount" />
      <el-table-column label="到款时间1" align="center" prop="receiveTimeOne" />
      <el-table-column label="到款金额1" align="center" prop="receiveAmountOne" />
      <el-table-column label="备注" align="center" prop="remark" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['web:contractinformation:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['web:contractinformation:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改收款合同信息对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="合同编号" prop="contractNo">
          <el-input v-model="form.contractNo" placeholder="请输入合同编号" />
        </el-form-item>
        <el-form-item label="合同年份" prop="contractYear">
          <el-input v-model="form.contractYear" placeholder="请输入合同年份" />
        </el-form-item>
        <el-form-item label="是否为代购代销" prop="purchaseSaleAgency">
          <el-input v-model="form.purchaseSaleAgency" placeholder="请输入是否为代购代销" />
        </el-form-item>
        <el-form-item label="项目编号" prop="projectNumber">
          <el-input v-model="form.projectNumber" placeholder="请输入项目编号" />
        </el-form-item>
        <el-form-item label="合同名称" prop="contractName">
          <el-input v-model="form.contractName" placeholder="请输入合同名称" />
        </el-form-item>
        <el-form-item label="框架协议" prop="frame">
          <el-input v-model="form.frame" placeholder="请输入框架协议" />
        </el-form-item>
        <el-form-item label="对方单位名称" prop="counterpartyName">
          <el-input v-model="form.counterpartyName" placeholder="请输入对方单位名称" />
        </el-form-item>
        <el-form-item label="联系人" prop="contact">
          <el-input v-model="form.contact" placeholder="请输入联系人" />
        </el-form-item>
        <el-form-item label="电话" prop="phone">
          <el-input v-model="form.phone" placeholder="请输入电话" />
        </el-form-item>
        <el-form-item label="合同金额" prop="conteactAmount">
          <el-input v-model="form.conteactAmount" placeholder="请输入合同金额" />
        </el-form-item>
        <el-form-item label="项目负责人" prop="projectLeader">
          <el-input v-model="form.projectLeader" placeholder="请输入项目负责人" />
        </el-form-item>
        <el-form-item label="合同签订部门" prop="contractSignDepartment">
          <el-input v-model="form.contractSignDepartment" placeholder="请输入合同签订部门" />
        </el-form-item>
        <el-form-item label="合同经办人" prop="contractAgent">
          <el-input v-model="form.contractAgent" placeholder="请输入合同经办人" />
        </el-form-item>
        <el-form-item label="录入情况" prop="inputCondition">
          <el-input v-model="form.inputCondition" placeholder="请输入录入情况" />
        </el-form-item>
        <el-form-item label="合同签订日期" prop="conteactSignDate">
          <el-date-picker clearable
            v-model="form.conteactSignDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择合同签订日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="合同开始时间" prop="conteactStartDate">
          <el-date-picker clearable
            v-model="form.conteactStartDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择合同开始时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="合同结束时间" prop="conteactEndDate">
          <el-date-picker clearable
            v-model="form.conteactEndDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择合同结束时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="合同结算条款1" prop="settlementClause">
          <el-input v-model="form.settlementClause" placeholder="请输入合同结算条款1" />
        </el-form-item>
        <el-form-item label="条款金额1" prop="clauseAmount">
          <el-input v-model="form.clauseAmount" placeholder="请输入条款金额1" />
        </el-form-item>
        <el-form-item label="合同签订情况" prop="contractSignCondition">
          <el-input v-model="form.contractSignCondition" placeholder="请输入合同签订情况" />
        </el-form-item>
        <el-form-item label="合同执行进度" prop="contractExecuteSchedule">
          <el-input v-model="form.contractExecuteSchedule" placeholder="请输入合同执行进度" />
        </el-form-item>
        <el-form-item label="开票总额" prop="totalInvoice">
          <el-input v-model="form.totalInvoice" placeholder="请输入开票总额" />
        </el-form-item>
        <el-form-item label="开票时间1" prop="invoiceTimeOne">
          <el-date-picker clearable
            v-model="form.invoiceTimeOne"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择开票时间1">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="开票金额1" prop="invoiceAmountOne">
          <el-input v-model="form.invoiceAmountOne" placeholder="请输入开票金额1" />
        </el-form-item>
        <el-form-item label="开票人1" prop="drawerOne">
          <el-input v-model="form.drawerOne" placeholder="请输入开票人1" />
        </el-form-item>
        <el-form-item label="发票号1" prop="invoiceNumberOne">
          <el-input v-model="form.invoiceNumberOne" placeholder="请输入发票号1" />
        </el-form-item>
        <el-form-item label="到款总额" prop="receiveTotalAmount">
          <el-input v-model="form.receiveTotalAmount" placeholder="请输入到款总额" />
        </el-form-item>
        <el-form-item label="到款时间1" prop="receiveTimeOne">
          <el-input v-model="form.receiveTimeOne" placeholder="请输入到款时间1" />
        </el-form-item>
        <el-form-item label="到款金额1" prop="receiveAmountOne">
          <el-input v-model="form.receiveAmountOne" placeholder="请输入到款金额1" />
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input v-model="form.remark" placeholder="请输入备注" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import  {listContractInformation, getContractinformation, delContractinformation, addContractinformation, updateContractinformation}  from "@/api/web/contractInformation";

export default {
  name: "Contractinformation",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 收款合同信息表格数据
      contractinformationList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        contractNo: null,
        contractType: null,
        contractYear: null,
        purchaseSaleAgency: null,
        projectNumber: null,
        contractName: null,
        frame: null,
        counterpartyName: null,
        clientType: null,
        contact: null,
        phone: null,
        conteactAmount: null,
        projectLeader: null,
        contractSignDepartment: null,
        contractAgent: null,
        inputCondition: null,
        conteactSignDate: null,
        conteactStartDate: null,
        conteactEndDate: null,
        settlementClause: null,
        clauseAmount: null,
        contractSignCondition: null,
        contractExecuteSchedule: null,
        totalInvoice: null,
        invoiceTimeOne: null,
        invoiceAmountOne: null,
        drawerOne: null,
        invoiceNumberOne: null,
        receiveTotalAmount: null,
        receiveTimeOne: null,
        receiveAmountOne: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询收款合同信息列表 */
    getList() {
      this.loading = true;
      listContractInformation(this.queryParams).then(response => {
        this.contractinformationList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        contractNo: null,
        contractType: null,
        contractYear: null,
        purchaseSaleAgency: null,
        projectNumber: null,
        contractName: null,
        frame: null,
        counterpartyName: null,
        clientType: null,
        contact: null,
        phone: null,
        conteactAmount: null,
        projectLeader: null,
        contractSignDepartment: null,
        contractAgent: null,
        inputCondition: null,
        conteactSignDate: null,
        conteactStartDate: null,
        conteactEndDate: null,
        settlementClause: null,
        clauseAmount: null,
        contractSignCondition: null,
        contractExecuteSchedule: null,
        totalInvoice: null,
        invoiceTimeOne: null,
        invoiceAmountOne: null,
        drawerOne: null,
        invoiceNumberOne: null,
        receiveTotalAmount: null,
        receiveTimeOne: null,
        receiveAmountOne: null,
        createTime: null,
        createBy: null,
        updateTime: null,
        updateBy: null,
        remark: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加收款合同信息";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getContractinformation(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改收款合同信息";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateContractinformation(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addContractinformation(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除收款合同信息编号为"' + ids + '"的数据项？').then(function() {
        return delContractinformation(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('web/contractinformation/export', {
        ...this.queryParams
      }, `contractinformation_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
